<!DOCTYPE html><html lang="zh-CN" data-theme="dark"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>ES6 新语法 | XiaoZhang’s Blog</title><meta name="keywords" content="前端,ES6"><meta name="author" content="XiaoZhang,邮箱"><meta name="copyright" content="XiaoZhang"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#0d0d0d"><meta name="description" content="let 关键字特点    var 关键字    let 关键字变量提升    √    ×作用域    没有块级作用域，是函数作用域    有块级作用域重复声明    √    ×重新赋值    √    √变量提升 console.log(age);let age &#x3D; 38;image-20200701114547150 作用域 for (var i &#x3D; 0; i &lt; 10; i++) {">
<meta property="og:type" content="article">
<meta property="og:title" content="ES6 新语法">
<meta property="og:url" content="https://zhang_shaolong.gitee.io/posts/3ebb.html">
<meta property="og:site_name" content="XiaoZhang’s Blog">
<meta property="og:description" content="let 关键字特点    var 关键字    let 关键字变量提升    √    ×作用域    没有块级作用域，是函数作用域    有块级作用域重复声明    √    ×重新赋值    √    √变量提升 console.log(age);let age &#x3D; 38;image-20200701114547150 作用域 for (var i &#x3D; 0; i &lt; 10; i++) {">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://api.ixiaowai.cn/gqapi/gqapi.php">
<meta property="article:published_time" content="2021-10-19T14:37:00.000Z">
<meta property="article:modified_time" content="2021-11-30T09:23:19.658Z">
<meta property="article:author" content="XiaoZhang">
<meta property="article:tag" content="前端">
<meta property="article:tag" content="ES6">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://api.ixiaowai.cn/gqapi/gqapi.php"><link rel="shortcut icon" href="/img/dvoe.png"><link rel="canonical" href="https://zhang_shaolong.gitee.io/posts/3ebb"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?ffcbb436e2f4b0326f38f622b85c0f07";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'mediumZoom',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"top-right"},
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'ES6 新语法',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: false,
  postUpdate: '2021-11-30 17:23:19'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><div class="aplayer" data-id="7031037814" data-server="netease" data-type="playlist" data-fixed="true" data-listFolded="false" data-order="random" data-preload="none"></div><link rel="stylesheet" href="https://cdn.bootcss.com/aplayer/1.10.1/APlayer.min.css"><script src="https://cdn.bootcss.com/aplayer/1.10.1/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/npm/meting@1.2.0/dist/Meting.min.js"></script><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    document.addEventListener('pjax:complete', detectApple)})(window)</script><link rel="stylesheet" href="/css/bg.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/static-butterfly/dist/css/index.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/l-lin/font-awesome-animation/dist/font-awesome-animation.min.css"  media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://zhang_shaolong.gitee.io/css/bg.css"><div id="aplayer"></div><!--script(src="https://cdn.jsdelivr.net/gh/radium-bit/res@master/live2d/autoload.js" async)--><!--script(src="https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js" async)--><!-- hexo injector head_end start --><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-footer-beautify@1.0.0/lib/runtime.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiperstyle.css" media="print" onload="this.media='all'"><!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.4.0"><link rel="alternate" href="/atom.xml" title="XiaoZhang’s Blog" type="application/atom+xml">
</head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/avatar.jpeg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">25</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">20</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/navigation/"><i class="fa-fw fas fa-map"></i><span> 导航</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 博客</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/photos/"><i class="fa-fw fas fa-camera"></i><span> 相册</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/bb/"><i class="fa-fw fas fa-bomb"></i><span> 动态</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友人帐</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-comments"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/my-profile/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://api.ixiaowai.cn/gqapi/gqapi.php')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">XiaoZhang’s Blog</a><div id="he-plugin-simple"></div></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/navigation/"><i class="fa-fw fas fa-map"></i><span> 导航</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 博客</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 娱乐</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/photos/"><i class="fa-fw fas fa-camera"></i><span> 相册</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/bb/"><i class="fa-fw fas fa-bomb"></i><span> 动态</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友人帐</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-comments"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/my-profile/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">ES6 新语法</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-10-19T14:37:00.000Z" title="发表于 2021-10-19 22:37:00">2021-10-19</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-11-30T09:23:19.658Z" title="更新于 2021-11-30 17:23:19">2021-11-30</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="ES6 新语法"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><p>let 关键字<br>特点    var 关键字    let 关键字<br>变量提升    √    ×<br>作用域    没有块级作用域，是函数作用域    有块级作用域<br>重复声明    √    ×<br>重新赋值    √    √<br>变量提升</p>
<p>console.log(age);<br>let age = 38;<br>image-20200701114547150</p>
<p>作用域</p>
<p>for (var i = 0; i &lt; 10; i++) {}<br>console.log(i);</p>
<p>for (let n = 0; i &lt; 10; i++) {}<br>console.log(n);<br>image-20200701114808765</p>
<p>图中可对比看出，如果用 var 声明，在循环外部还是可以使用 i 变量；但用 let 声明变量，循环外部不可以使用 n 变量</p>
<p>不可重复声明</p>
<p>let num2 = 10;<br>let num2 = 20;<br>console.log(“num2: “, num2);<br>image-20200701115104294</p>
<p>重新赋值</p>
<p>let num2 = 10;<br>num2 = 20;<br>console.log(“num2: “, num2);<br>image-20200701115202044</p>
<p> const 关键字<br>使用场景</p>
<p>一些不会变化的值，比如圆周率 PI<br>大事件项目中，保存基地址<br>没有变量提升</p>
<p>image-20200701115648469</p>
<p>有块级作用域</p>
<p>image-20200701115756085</p>
<p>不能重复声明</p>
<p>image-20200701115830566</p>
<p>不能重新赋值（声明必须要初始化）</p>
<p>image-20200701115846798</p>
<p> 解构赋值<br> 对象解构<br>取对象中属性的值，赋值给变量。</p>
<p>例如对于如下对象来说，在 ES5 与 ES6 中将对象赋值于变量的方式</p>
<p>let obj = {<br>  name: “波波”,<br>  age: 38,<br>  gender: “男”,<br>  score: 88,<br>};<br>ES5 中的写法</p>
<p>let name1 = obj.name;<br>let age1 = obj.age;<br>let gender1 = obj.gender;<br>let score1 = obj.score;<br>console.log(name1, age1, gender1, score1);<br>ES6 中的写法</p>
<p>定义变量名</p>
<p>let { name: name2, age: age2, gender: gender2, score: score2 } = obj;<br>console.log(name2, age2, gender2, score2);<br>变量名可与属性名一致</p>
<p>let { name: name, age: age, gender: gender, score: score } = obj;<br>console.log(name, age, gender, score);<br>当变量名与属性名一致时，可以省略变量名</p>
<p>let { name, age, gender, score } = obj;<br>console.log(name, age, gender, score);<br>以上代码的输出结果都为下图所示</p>
<p>image-20200701153427629</p>
<p>当简写时，对象中没有的属性会赋值为 undefined</p>
<p>let obj = {<br>  name: “波波”,<br>  age: 38,<br>  gender: “男”,<br>  score: 88,<br>};<br>let { name, age, gender, fenshu } = obj;<br>console.log(name, age, gender, fenshu);<br>image-20200701153747123</p>
<p>简写与全写可以一起用</p>
<p>let { name, age, gender, score: fenshu } = obj;<br>console.log(name, age, gender, fenshu);<br>image-20200701153937328</p>
<p>设置默认值。当对象中没有此属性时会赋值为默认值而不是 undefined。如果对象中存在这个属性，那么将赋值为对象中的属性，而不是默认值。</p>
<p>let { name, age, gender, score: fenshu, height = 180 } = obj;<br>console.log(name, age, gender, fenshu, height);<br>image-20200701154223592</p>
<p>赋值一个除了某个属性不存在，但存在其余属性的对象</p>
<p>let obj = {<br>  name: “波波”,<br>  age: 38,<br>  gender: “男”,<br>  score: 100,<br>};</p>
<p>// obj2相当于是obj对象里面除了name属性之外的属性组成的一个对象<br>let { name, …obj2 } = obj;<br>console.log(obj2); // { age: 38, gender: ‘男’, score: 100 }<br>image-20200702092507243</p>
<p> 数组解构<br>把数组中每一个元素的值依次的赋值给变量。声明如下数组：</p>
<p>// 声明一个数组<br>let arr = [10, 20, 30, 40];<br>ES5 中的写法</p>
<p>let num1 = arr[0];<br>let num2 = arr[1];<br>let num3 = arr[2];<br>let num4 = arr[3];<br>console.log(num1, num2, num3, num4);<br>ES6 中的写法</p>
<p>基础写法–一一对应</p>
<p>let [num1, num2, num3, num4] = arr;<br>console.log(num1, num2, num3, num4);<br>image-20200701155309108</p>
<p>默认值与没有值时与对象解构一致。</p>
<p>let [num1, num2, num3, num4, num5] = arr;<br>console.log(num1, num2, num3, num4, num5); // num5为undefined<br>let [num1, num2, num3, num4, num5=5] = arr;<br>console.log(num1, num2, num3, num4, num5); // num5为5<br> 解构赋值结合函数声明<br>ES5 中的写法</p>
<p>function test1(obj) {<br>  console.log(obj.name, obj.age, obj.gender);<br>}<br>test1({<br>  name: “波波”,<br>  age: 38,<br>  gender: “男”,<br>});<br>ES6 中的写法</p>
<p>function test2({ name, age, gender, height = 180 }) {<br>  console.log(name, age, gender, height);<br>}<br>test2({<br>  name: “波波”,<br>  age: 38,<br>  gender: “男”,<br>});<br>test2({<br>  name: “波波”,<br>  age: 38,<br>  gender: “男”,<br>  height: 160,<br>});<br>image-20200701160704150</p>
<p> 箭头函数<br>简单来说，箭头函数就是匿名函数的一个简写。</p>
<p>// 1. 普通的匿名函数<br>let fn = function (name) {<br>  console.log(“my name is “, name);<br>};<br>fn(“波波”);</p>
<p>// 2. 箭头函数<br>let fn1 = (name) =&gt; console.log(“my name is “, name);<br>fn1(“波波”);<br>image-20200701161344962</p>
<p>简写规则：</p>
<p>function 改成 =&gt;，=&gt; 可以读成 goes to</p>
<p>如果只有一个形参，那就可以省略形参小括号</p>
<p>如果不是一个形参（0 个或多个），那就不能省略形参小括号</p>
<p>如果函数体只有一句话，那就可以省略函数体的大括号</p>
<p>如果函数体只有一句话，并且这一句话是 return 返回值，那 return 也要省略</p>
<p>let fn1 = function (name) {<br>  return name + “你好吗?”;<br>};<br>let fn1 = (name) =&gt; name + “你好吗?”;<br>如果函数体不是一句话，那就不能省略这个大括号</p>
<p>let fn2 = function (num1, num2) {<br>  console.log(num1 + num2);<br>  return num1 + num2 + 30;<br>};</p>
<p>let fn2 = (num1, num2) =&gt; {<br>  console.log(num1 + num2);<br>  return num1 + num2 + 30;<br>};<br>无参数，一句话</p>
<p>let fn1 = function () {<br>  console.log(“你好吗”);<br>};<br>let f1 = () =&gt; console.log(“你好吗”);<br>一个参数，一句话</p>
<p>let fn2 = function (name) {<br>  console.log(name + “你好吗”);<br>};<br>let fn2 = (name) =&gt; console.log(name + “你好吗”);<br>两个参数，一句话</p>
<p>let fn3 = function (name, age) {<br>  console.log(name + “你好吗,你的年龄是” + age);<br>};<br>let fn3 = (name, age) =&gt; console.log(name + “你好吗,你的年龄是” + age);<br>一个参数，一个 return</p>
<p>let fn4 = function (age) {<br>  return age + 10;<br>};<br>let fn4 = (age) =&gt; age + 10;<br>两个参数，多句</p>
<p>let fn5 = function (name, age) {<br>  console.log(name + “你好吗”);<br>  return age + 10;<br>};<br>let fn5 = (name, age) =&gt; {<br>  console.log(name + “你好吗”);<br>  return age + 10;<br>};<br> this 指向<br>箭头函数的 this 由上下文环境决定，其原理就是将箭头函数的上下文 this 保存，在箭头函数内部使用这个被保存的 this。使用注意：</p>
<p>不是什么时候都使用箭头函数</p>
<p>不要用 new 关键字调用箭头函数</p>
<p>var Fn = (name, age) =&gt; {<br>    this.name = name<br>    this.age = age<br>}<br>var obj = new Fn(‘伦哥’, 10) // Fn is not a constructor<br>箭头函数的 this 是由上下文环境决定，而不是 new 关键字来决定</p>
<p>var obj = {<br>    name: ‘波波’,<br>    sayHi: function () {<br>        console.log(‘我的名字是：’, this.name) // 我的名字是： 波波<br>        // 上文环境<br>        setTimeout(() =&gt; {<br>            console.log(‘我的名字是：’, this.name) // 我的名字是： 波波<br>        }, 2000)<br>        // 下文环境<br>    }<br>}<br>obj.sayHi()<br>当多层箭头函数套用时，那么里面的 this 指向都与最外层的 this 指向一致。</p>
<p>var obj = {<br>    name: ‘波波’,<br>    sayHi: function () {<br>        console.log(‘我的名字是1：’, this.name)<br>        // 上文环境<br>        setTimeout(() =&gt; {<br>            console.log(‘我的名字是2：’, this.name)<br>            setTimeout(() =&gt; {<br>                console.log(‘我的名字是3：’, this.name)<br>                setTimeout(() =&gt; {<br>                    console.log(‘我的名字是4：’, this.name)<br>                }, 1000)<br>            }, 1000)<br>        }, 1000)<br>        // 下文环境<br>    }<br>}<br>obj.sayHi()<br>image-20200702094635888</p>
<p> 对象成员简写<br>let name = “千里”;<br>let age = 18;<br>let gender = “man”;<br>let score = 10;</p>
<p>// es6<br>let obj = {<br>  name,<br>  age,<br>  gender,<br>  score,<br>  sayHi() {<br>    console.log(“哈哈”);<br>  },<br>};<br>console.log(obj);<br>obj.sayHi();<br>image-20200701164157212</p>
<p>在这种写法中，如果传入一个没有赋值的变量，那么就会报错。例如：</p>
<p>let name = “千里”;<br>let age = 18;<br>let gender = “man”;<br>let score = 10;</p>
<p>// es6<br>let obj = {<br>    name,<br>    age,<br>    gender,<br>    score,<br>    // fenshu, // 会发生报错，因为外部没有此变量，可以修改为下面的写法<br>    fenshu:score,<br>    sayHi() {<br>        console.log(“哈哈”);<br>    },<br>};<br>console.log(obj);<br>obj.sayHi();<br> 扩展（展开）运算符<br> 对象展开<br>// 声明一个对象<br>let chinese = {<br>    skin: “yellow”,<br>    hair: “black”,<br>    sayHi() {<br>        console.log(“Are you eat?”);<br>    },<br>};</p>
<p>let CXK = {<br>    slill: “jump sing rap and play basketball”,<br>    song: “啊哈哈哈”,<br>};<br>let linge = {<br>    // skin: “yellow”,<br>    // hair: “black”,<br>    // sayHi() {<br>    //   console.log(“Are you eat?”);<br>    // },<br>    // slill: “jump sing rap and play basketball”,<br>    // song: “啊哈哈哈”,<br>    // 展开语法 等同于上方写法<br>    …chinese,<br>    …CXK,<br>};<br>console.log(linge);<br>image-20200701165348837</p>
<p>当新增属性时，直接添加即可。如果重新定义已经存在的，那么覆盖原来的。</p>
<p>let linge = {<br>  …chinese,<br>  …CXK,<br>  gender: “Man”,<br>  hair: “白发苍苍”,<br>};<br>image-20200701165728791</p>
<p> 数组展开<br>与对象展开类似。</p>
<p>let arr1 = [10, 20, 30];<br>let arr2 = [40, 50, 60];<br>let arr3 = […arr1, …arr2, 70];<br>console.log(arr3);<br>image-20200701170324837</p>
<p>使用场景：</p>
<p>数组的拼接</p>
<p>求最大 / 小值</p>
<p>let arr1 = [10, 23, 54, 446, 56, 2];<br>let max = Math.max(…arr1);<br>console.log(max);<br> 数据类型 set<br>作用和数组类型，和数组不同的是 set 不能存放重复的元素。</p>
<p>基本使用</p>
<p>let set1 = new Set([10, 20, 30, 40, 10, 20, 30, 40, 50]);<br>console.log(set1);<br>image-20200701170935727</p>
<p>数组去重</p>
<p>let arr = [10, 20, 30, 10, 20, 30, 20, 10, 33, 200];<br>let set = new Set(arr);<br>let arrNew = […set];<br>console.log(arrNew);<br>image-20200701171115524</p>
<p>也可以改写为如下：</p>
<p>let arr = [10, 20, 30, 10, 20, 30, 20, 10, 33, 200];<br>let arrNew = […new Set(arr)];<br>console.log(arrNew);<br> 模板字符串<br>模板字符串会保留原样字符串格式，以及可以占位。其语法为反引号 ``</p>
<p>let author = “波波”;<br>let str1 = <code>静夜思     $&#123;author&#125; 哈哈哈</code>;<br>console.log(str1);<br>image-20200701171652048</p>
<p>let name = “xiaokang”;<br>let age = 12;<br>function test() {<br>  return “test”;<br>}<br>console.log(<code>my name is $&#123;name&#125; and age is $&#123;age&#125;. $&#123;test()&#125;</code>);<br>image-20200701172133560</p>
<p> 补充数组的方法<br>forEach</p>
<p>无返回值</p>
<p>let arr = [10, 20, 30, 40];<br>arr.forEach(function (item, index) {<br>  // item 遍历出的每一项<br>  // index 遍历出来的每一项对应的索引<br>  console.log(item, index);<br>});<br>map</p>
<p>有返回值。</p>
<p>let arr = [10, 20, 30, 40];<br>let arrNew = arr.map(function (item, index) {<br>  // item 遍历出的每一项<br>  // index 遍历出来的每一项对应的索引<br>  //   console.log(item, index);<br>  return item * item;<br>});<br>console.log(arrNew);<br>filter</p>
<p>let arr = [10, 20, 11, 21, 30, 31, 23, 43];<br>let arrNew = arr.filter((item, index) =&gt; {<br>  console.log(item, index);<br>  // 如果条件成立,返回当前项<br>  return item % 2 == 0;<br>});<br>console.log(arrNew); //[ 10, 20, 30 ]<br>数组的其他应用</p>
<p>数组降维</p>
<p>将二维数组降维为一维数组</p>
<p>// 将二维数组将为一维数组<br>var arr = [[10, 20], [30, 40, 50], [60, 79, 80]]<br>var arrNew = []<br>arr.forEach(v =&gt; {<br>    arrNew.push(…v)<br>})<br>console.log(arrNew); // [10, 20, 30, 40, 50, 60, 79, 80]<br>数组的去重（排序法）</p>
<p>var arr = [10, 20, 30, 23, 4, 512, 20, 10];<br>var arrNew = [];<br>arr.sort((a, b) =&gt; {<br>  return a - b;<br>});<br>console.log(arr); // [4, 10, 10, 20, 20, 23, 30, 512];<br>arr.forEach((v, i) =&gt; {<br>  if (v != arr[i + 1]) {<br>    arrNew.push(v);<br>  }<br>});<br>console.log(arrNew); // [ 4, 10, 20, 23, 30, 512 ]<br>数组去重（对象法）</p>
<p>原理：利用对象属性不能同名。</p>
<p>// 使用对象法<br>var obj = {};<br>var arrNew = [];<br>// 遍历要去重的数组<br>arrNew.forEach((v) =&gt; {<br>  if (obj[v] == undefined) {<br>    arrNew.push(v); // 不存在九江这个v存起来<br>    obj[v] = 1; // 随意写，作为属性的值（避免undefined）<br>  }<br>});<br>数组升维</p>
<p>假设从后端拿到的数据为如下格式：</p>
<p>var arr = [<br>    { type: “电子产品”, name: “iPhone”, price: 8888 },<br>    { type: “家具”, name: “桌子”, price: 100 },<br>    { type: “食品”, name: “瓜子”, price: 10 },<br>    { type: “家具”, name: “椅子”, price: 380 },<br>    { type: “电子产品”, name: “小米手机”, price: 1380 },<br>    { type: “食品”, name: “辣条”, price: 5 },<br>    { type: “食品”, name: “咖啡”, price: 50 },<br>];<br>第一种：</p>
<p>var obj = {}; //将测type有没有重复的<br>var arrNew = []; // 升级后的二维数组<br>// 1. 将type去重，找出所有的产品类型<br>// 遍历这个arr一维数组<br>arr.forEach((v) =&gt; {<br>  if (obj[v.type] == undefined) {<br>    obj[v.type] = 1;<br>    //   把这个数组放到arrNew中<br>    arrNew.push({<br>      type: v.type,<br>      data: [v],<br>    });<br>  } else {<br>    // 判断当前v输入arrNew中的哪一类<br>    arrNew.forEach((v2, j) =&gt; {<br>      if (v.type == v2.type) {<br>        arrNew[j].data.push(v);<br>      }<br>    });<br>  }<br>});<br>console.log(arrNew);<br>第二种：</p>
<p>var obj = {}; //将测type有没有重复的<br>var arrNew = []; // 升级后的二维数组<br>var index = 0; // 用于记录索引<br>arr.forEach((v) =&gt; {<br>  if (obj[v.type] == undefined) {<br>    obj[v.type] = index++;<br>    //   把这个数组放到arrNew中<br>    arrNew.push({<br>      type: v.type,<br>      data: [v],<br>    });<br>  } else {<br>    var _index = obj[v.type];<br>    arrNew[_index].data.push(v);<br>  }<br>});<br>console.log(arrNew);<br>image-20200702112619895</p>
<p> babel 将 ES6 代码转为 ES5</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:邮箱">XiaoZhang</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://zhang_shaolong.gitee.io/posts/3ebb.html">https://zhang_shaolong.gitee.io/posts/3ebb.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://zhang_shaolong.gitee.io" target="_blank">XiaoZhang’s Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E5%89%8D%E7%AB%AF/">前端</a><a class="post-meta__tags" href="/tags/ES6/">ES6</a></div><div class="post_share"><div class="social-share" data-image="https://api.ixiaowai.cn/gqapi/gqapi.php" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/posts/dd04.html"><img class="prev-cover" src="https://api.ixiaowai.cn/gqapi/gqapi.php" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">butterfly 主题使用文档</div></div></a></div><div class="next-post pull-right"><a href="/posts/c16e.html"><img class="next-cover" src="/../cover/algorithm.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">算法练习(一）之贪心算法</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/posts/bed3,.html" title="赋值、浅拷贝和深拷贝的区别"><img class="cover" src="/../cover/copy.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-06-30</div><div class="title">赋值、浅拷贝和深拷贝的区别</div></div></a></div><div><a href="/posts/81.html" title="CSS盒模型"><img class="cover" src="/../cover/business.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-08-23</div><div class="title">CSS盒模型</div></div></a></div><div><a href="/posts/f40f.html" title="JavaScript类型判断"><img class="cover" src="/../cover/JavaScript.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-11-17</div><div class="title">JavaScript类型判断</div></div></a></div><div><a href="/posts/488c.html" title="JS函数柯里化"><img class="cover" src="/../cover/currying.webp" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-12-07</div><div class="title">JS函数柯里化</div></div></a></div><div><a href="/posts/dc34.html" title="Socket.IO使用"><img class="cover" src="/../cover/socket.webp" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-11-30</div><div class="title">Socket.IO使用</div></div></a></div><div><a href="/posts/9d4c.html" title="html标签"><img class="cover" src="/../cover/business.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-04-02</div><div class="title">html标签</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/avatar.jpeg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">XiaoZhang</div><div class="author-info__description">彼方尚有荣光在！！！ </div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">25</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">20</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/zhang_shaolong"><i class="fab fa-github-alt"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">有朋自远方来，不亦乐乎！</div></div><div class="sticky_layout"><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/posts/89a6.html" title="总结(1.16)"><img src="https://api.ixiaowai.cn/gqapi/gqapi.php" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="总结(1.16)"/></a><div class="content"><a class="title" href="/posts/89a6.html" title="总结(1.16)">总结(1.16)</a><time datetime="2022-01-16T13:51:00.000Z" title="发表于 2022-01-16 21:51:00">2022-01-16</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/488c.html" title="JS函数柯里化"><img src="/../cover/currying.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JS函数柯里化"/></a><div class="content"><a class="title" href="/posts/488c.html" title="JS函数柯里化">JS函数柯里化</a><time datetime="2021-12-07T06:37:00.000Z" title="发表于 2021-12-07 14:37:00">2021-12-07</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/2f90.html" title="总结(12.5)"><img src="https://tva4.sinaimg.cn/large/87c01ec7gy1frmmw9573mj21kw0w0npk.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="总结(12.5)"/></a><div class="content"><a class="title" href="/posts/2f90.html" title="总结(12.5)">总结(12.5)</a><time datetime="2021-12-05T03:17:00.000Z" title="发表于 2021-12-05 11:17:00">2021-12-05</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/dc34.html" title="Socket.IO使用"><img src="/../cover/socket.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Socket.IO使用"/></a><div class="content"><a class="title" href="/posts/dc34.html" title="Socket.IO使用">Socket.IO使用</a><time datetime="2021-11-30T01:19:00.000Z" title="发表于 2021-11-30 09:19:00">2021-11-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/b9e7e805.html" title="总结(11.27)"><img src="https://tva1.sinaimg.cn/large/0060lm7Tly1ftg6oqfp3aj318g0p0k4h.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="总结(11.27)"/></a><div class="content"><a class="title" href="/posts/b9e7e805.html" title="总结(11.27)">总结(11.27)</a><time datetime="2021-11-27T08:55:00.000Z" title="发表于 2021-11-27 16:55:00">2021-11-27</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button id="chat_btn" type="button" title="rightside.chat_btn"><i class="fas fa-sms"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/medium-zoom/dist/medium-zoom.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script src="/js/search/local-search.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: 'eHF7sUaBksaicGG9E3R7cdnJ-gzGzoHsz',
      appKey: 'nkwWdcso9uIl84CMuiYeg94T',
      placeholder: 'ヾﾉ≧∀≦)o来啊，快活啊!',
      avatar: 'monsterid',
      meta: 'nick,mail,QQ'.split(','),
      pageSize: '12',
      lang: 'zh-CN',
      recordIP: false,
      serverURLs: '',
      emojiCDN: '',
      emojiMaps: "",
      enableQQ: true,
      path: window.location.pathname,
      requiredFields: ["nick,mail"],
      visitor: false
    }, null))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.jsdelivr.net/gh/HCLonely/Valine@latest/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><canvas id="universe"></canvas><script src="https://myhkw.cn/player/js/jquery.min.js" type="text/javascript"></script><script defer src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="/js/star.js"></script><script async src="/js/diytitle.js"></script><script async data-pjax src="/js/randombg.js"></script><script src="https://widget.qweather.net/simple/static/js/he-simple-common.js?v=2.0"></script><script async src="/js/weather.js"></script><script defer src="https://cdn.jsdelivr.net/npm/hexo-theme-volantis@latest/source/js/issues.min.js"></script><script src="/js/universe.js"></script><script src="https://npm.elemecdn.com/jquery@latest/dist/jquery.min.js"></script><script> $(".category-list-count").prepend("<i class=\"fas fa-book\"></i>");</script><script> $(".category-list-item").eq(0).insertAfter($(".gallery-group-name").eq(0))</script><script> $(".category-list-item").eq(1).insertAfter($(".gallery-group-name").eq(1))</script><script> $(".category-list-item").eq(2).insertAfter($(".gallery-group-name").eq(2))</script><script> $(".category-list-item").eq(3).insertAfter($(".gallery-group-name").eq(3))</script><script> $(".category-list-item").eq(4).insertAfter($(".gallery-group-name").eq(4))</script><script> $(".category-list-item").eq(5).insertAfter($(".gallery-group-name").eq(5))</script><script> $(".category-list-item a").hide();</script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = false;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-show-text" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-show-text.min.js" data-mobile="false" data-text="富强,民主,文明,和谐,自由,平等,公正,法治,爱国,敬业,诚信,友善" data-fontsize="18px" data-random="true" async="async"></script><script src="//code.tidio.co/mxavk34b68alwnegypahsbiwew7digod.js" async="async"></script><script>function onTidioChatApiReady() {
  window.tidioChatApi.hide();
  window.tidioChatApi.on("close", function() {
    window.tidioChatApi.hide();
  });
}
if (window.tidioChatApi) {
  window.tidioChatApi.on("ready", onTidioChatApiReady);
} else {
  document.addEventListener("tidioChat-ready", onTidioChatApiReady);
}

var chatBtnFn = () => {
  document.getElementById("chat_btn").addEventListener("click", function(){
    window.tidioChatApi.show();
    window.tidioChatApi.open();
  });
}
chatBtnFn()
</script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = [
  'title',
  '#config-diff',
  '#body-wrap',
  '#rightside-config-hide',
  '#rightside-config-show',
  '.js-pjax'
]

if (false) {
  pjaxSelectors.unshift('meta[property="og:image"]', 'meta[property="og:title"]', 'meta[property="og:url"]')
}

var pjax = new Pjax({
  elements: 'a:not([target="_blank"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener scroll 
  window.removeEventListener('scroll', window.tocScrollFn)
  window.removeEventListener('scroll', scrollCollect)

  typeof preloader === 'object' && preloader.initLoading()
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof chatBtnFn === 'function' && chatBtnFn()
  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // Analytics
  if (false) {
    MtaH5.pgv()
  }

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()

  typeof preloader === 'object' && preloader.endLoading()
})

document.addEventListener('pjax:error', (e) => {
  if (e.request.status === 404) {
    pjax.loadUrl('/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start -->
  <script data-pjax src="https://cdn.jsdelivr.net/gh/Zfour/hexo-github-calendar@1.21/hexo_githubcalendar.js"></script>
  <script data-pjax>
        function GithubCalendarConfig(){
            var git_githubapiurl ="https://python-gitee-calendar-api.vercel.app/api?zhang_shaolong";
            var git_color =['#ebedf0', '#f1f8ff', '#dbedff', '#c8e1ff', '#79b8ff', '#2188ff', '#0366d6', '#005cc5', '#044289', '#032f62', '#05264c'];
            var git_user ="zhang_shaolong";
            var parent_div_git = document.getElementById('recent-posts');
            var git_div_html = '<div class="recent-post-item" style="width:100%;height:auto;padding:10px;"><div id="github_loading" style="width:10%;height:100%;margin:0 auto;display: block"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"  viewBox="0 0 50 50" style="enable-background:new 0 0 50 50" xml:space="preserve"><path fill="#d0d0d0" d="M25.251,6.461c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615V6.461z" transform="rotate(275.098 25 25)"><animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="0.6s" repeatCount="indefinite"></animateTransform></path></svg></div><div id="github_container"></div></div>';
            if(parent_div_git && location.pathname =='/'){
                console.log('已挂载github calendar')
                // parent_div_git.innerHTML=git_div_html+parent_div_git.innerHTML // 无报错，但不影响使用(支持pjax跳转)
                parent_div_git.insertAdjacentHTML("afterbegin",git_div_html) // 有报错，但不影响使用(支持pjax跳转)
            };
            GithubCalendar(git_githubapiurl,git_color,git_user)
        }
        if(document.getElementById('recent-posts')){
            GithubCalendarConfig()
        }
    </script>
    <style>#github_container{min-height:280px}@media screen and (max-width:650px) {#github_container{background-image:;min-height:0px}}</style>
    <style></style><script data-pjax>
  function butterfly_footer_beautify_injector_config(){
    var parent_div_git = document.getElementById('footer-wrap');
    var item_html = '<div id="workboard"></div><div id="ghbdages" style="overflow:hidden;max-height:90px;height:auto;text-align:center;margin-top:10px"><div class="swiper-wrapper"><div class="swiper-slide"><a class="github-badge" target="_blank" href="https://hexo.io/" style="margin-inline:5px" title="博客框架为Hexo_v5.4.0"><img src="https://img.shields.io/badge/Frame-Hexo-blue?style=flat&amp;logo=hexo" alt=""/></a><a class="github-badge" target="_blank" href="https://butterfly.js.org/" style="margin-inline:5px" title="主题版本Butterfly_v3.8.2"><img src="https://img.shields.io/badge/Theme-Butterfly-6513df?style=flat&amp;logo=bitdefender" alt=""/></a><a class="github-badge" target="_blank" href="https://www.jsdelivr.com/" style="margin-inline:5px" title="本站使用JsDelivr为静态资源提供CDN加速"><img src="https://img.shields.io/badge/CDN-jsDelivr-orange?style=flat&amp;logo=jsDelivr" alt=""/></a></div><div class="swiper-slide"><a class="github-badge" target="_blank" href="https://github.com/" style="margin-inline:5px" title="本站项目由Github托管"><img src="https://img.shields.io/badge/Source-Github-d021d6?style=flat&amp;logo=GitHub" alt=""/></a><a class="github-badge" target="_blank" href="http://creativecommons.org/licenses/by-nc-sa/4.0/" style="margin-inline:5px" title="本站采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可"><img src="https://img.shields.io/badge/Copyright-BY--NC--SA%204.0-d42328?style=flat&amp;logo=Claris" alt=""/></a></div></div></div><style>a.github-badge:hover:before {display:none}</style>';
    console.log('已挂载butterfly_footer_beautify')
    parent_div_git.insertAdjacentHTML("beforeend",item_html)
    }
  var elist = '/about/'.split(',');
  var cpage = location.pathname;
  var epage = 'all';
  var flag = 0;

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_footer_beautify_injector_config();
  }
  else if (epage === cpage){
    butterfly_footer_beautify_injector_config();
  }
  </script><script async src="/js/runtime.js"></script><script defer src="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.js"></script><script defer data-pjax src="https://unpkg.zhimg.com/hexo-butterfly-footer-beautify/lib/swiperbdage_init.min.js"></script><script data-pjax>
  function butterfly_swiper_injector_config(){
    var parent_div_git = document.getElementById('recent-posts');
    var item_html = '<div class="recent-post-item" style="height: auto;width: 100%"><div class="blog-slider swiper-container-fade swiper-container-horizontal" id="swiper_container"><div class="blog-slider__wrp swiper-wrapper" style="transition-duration: 0ms;"><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/dc34.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src="../cover/socket.webp" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2021-11-30</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/dc34.html&quot;);" href="javascript:void(0);" alt="">Socket.IO使用</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/dc34.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/bf72.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src="../img/垂直.png" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2021-10-24</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/bf72.html&quot;);" href="javascript:void(0);" alt="">一个盒子垂直水平居中有哪些方法？</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/bf72.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/a2b7.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src="../img/assist/image2.png" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2021-11-02</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/a2b7.html&quot;);" href="javascript:void(0);" alt="">使用VuePress搭建vue组件库</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/a2b7.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/213d.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src="../cover/business.jpg" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2021-05-12</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/213d.html&quot;);" href="javascript:void(0);" alt="">双飞翼布局和圣杯布局</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/213d.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div><div class="blog-slider__item swiper-slide" style="width: 750px; opacity: 1; transform: translate3d(0px, 0px, 0px); transition-duration: 0ms;"><a class="blog-slider__img" onclick="pjax.loadUrl(&quot;posts/3079.html&quot;);" href="javascript:void(0);" alt=""><img width="48" height="48" src="https://api.ixiaowai.cn/gqapi/gqapi.php" alt="" onerror="this.src=https://unpkg.zhimg.com/akilar-candyassets/image/loading.gif; this.onerror = null;"/></a><div class="blog-slider__content"><span class="blog-slider__code">2021-04-03</span><a class="blog-slider__title" onclick="pjax.loadUrl(&quot;posts/3079.html&quot;);" href="javascript:void(0);" alt="">盒模型</a><div class="blog-slider__text">再怎么看我也不知道怎么描述它的啦！</div><a class="blog-slider__button" onclick="pjax.loadUrl(&quot;posts/3079.html&quot;);" href="javascript:void(0);" alt="">详情       </a></div></div></div><div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets"></div></div></div>';
    console.log('已挂载butterfly_swiper')
    parent_div_git.insertAdjacentHTML("afterbegin",item_html)
    }
  var elist = 'undefined'.split(',');
  var cpage = location.pathname;
  var epage = 'all';
  var flag = 0;

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_swiper_injector_config();
  }
  else if (epage === cpage){
    butterfly_swiper_injector_config();
  }
  </script><script defer src="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.js"></script><script defer data-pjax src="https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper_init.js"></script><!-- hexo injector body_end end --></body></html>